package com.heima.tanhua.controller;

import com.heima.tanhua.commonResult.Result;
import com.heima.tanhua.dto.LikerAddDto;
import com.heima.tanhua.serivce.UserLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users/like")
public class UserLikeController {
    @Autowired
    private UserLikeService userLikeService;

    @PostMapping
    public Result addList(@RequestBody LikerAddDto dto) {
        Boolean res = userLikeService.addList(dto);
        if (!res) {
            return Result.error("添加失败");
        }
        return Result.success("添加成功");
    }

    @DeleteMapping
    public Result removeLike(@RequestParam String followId) {
        boolean res = userLikeService.removeLike(followId);
        if (!res) {
            return Result.error("取消失败");
        }
        return Result.success("取消成功");
    }

    @GetMapping
    public Result getLikeList(@RequestParam(required = false) String name,
                              @RequestParam Integer type,
                              @RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "10") Integer pageSize) {
        Result likeList = userLikeService.getLikeList(name, type, page, pageSize);
        return likeList;
    }
}
